package com.ruoyi.rocky.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.rocky.domain.PcSetting;
import com.ruoyi.rocky.service.PcSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@Validated
@RestController
@RequestMapping("/pcSetting")
@AllArgsConstructor
@Api(tags = "设置管理")
public class PcSettingController extends BaseController {
    @Autowired
    private PcSettingService pcSettingService;

    /**
     * 查询设置管理列表
     */
    @ApiOperation(value = "查询设置管理列表")
    @GetMapping("/list")
    public TableDataInfo list(PcSetting pcSetting) {
        startPage();
        List<PcSetting> list = pcSettingService.selectPcSettingList(pcSetting);
        return getDataTable(list);
    }

//    /**
//     * 导出设置管理列表
//     */
//    @ApiOperation(value = "导出设置管理列表")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, PcSetting pcSetting) {
//        List<PcSetting> list = pcSettingService.selectPcSettingList(pcSetting);
//        ExcelUtil<PcSetting> util = new ExcelUtil<PcSetting>(PcSetting.class);
//        util.exportExcel(response, list, "设置管理数据");
//    }

    /**
     * 获取设置管理详细信息
     */
    @ApiOperation(value = "获取设置管理详细信息")
    @GetMapping(value = "/{settingId}")
    public R getInfo(@PathVariable("settingId") Long settingId) {
        return R.ok(pcSettingService.selectPcSettingBySettingId(settingId));
    }

    /**
     * 新增设置管理
     */
    @ApiOperation(value = "新增设置管理")
    @PostMapping
    public R add(@RequestBody PcSetting pcSetting) {
        return R.ok(pcSettingService.insertPcSetting(pcSetting));
    }

    /**
     * 修改设置管理
     */
    @ApiOperation(value = "修改设置管理")
    @PutMapping
    public R edit(@RequestBody PcSetting pcSetting) {
        return R.ok(pcSettingService.updatePcSetting(pcSetting));
    }

    /**
     * 删除设置管理
     */
    @ApiOperation(value = "删除设置管理")
    @DeleteMapping("/{settingIds}")
    public R remove(@PathVariable Long[] settingIds) {
        return R.ok(pcSettingService.deletePcSettingBySettingIds(settingIds));
    }
}